/*
 * JVM_Reference.h
 *
 *  Created on: 10.12.2010
 *      Author: Tavin
 */

#include <stdint.h>




#ifndef JVM_HANDLE_H_
#define JVM_HANDLE_H_

#include "JVM_Class.h"

//typedef uint16_t JVM_HandleNumber_t;
typedef uint16_t JVM_MemoryAdress_t;


#define CLASS_POINTER_OFFSET			0


#define STATIC_DATA_OFFSET		4

#define INSTANCE_DATA_OFFSET	4


#define ARRAY_DATA_OFFSET		6
#define ARRAY_LENGHT_OFFSET		4


typedef struct {
	uint16_t dataSize;
	uint16_t referenceCounter;
	JVM_MemoryAdress_t dataAddress;
} JVM_Handle_t;






uint16_t  JVM_Handle_Init();
uint16_t  JVM_Handle_Clear(JVM_HandleNumber_t HandleNumber);
uint16_t  JVM_Handle_set(JVM_HandleNumber_t HandleNumber,uint16_t dataSize);


JVM_HandleNumber_t  JVM_Handle_new(uint16_t dataSize);
JVM_HandleNumber_t  JVM_Handle_newInstance(JVM_Class_t * class);
JVM_HandleNumber_t  JVM_Handle_newStatic(JVM_Class_t * class);
JVM_HandleNumber_t  JVM_Handle_newArray(uint16_t dataSize,JVM_Class_t * class);




void JVM_Handle_countUp(JVM_HandleNumber_t handleNumber);
void JVM_Handle_countDown(JVM_HandleNumber_t handleNumber);


uint16_t JVM_Handle_clearMemory(JVM_HandleNumber_t handleNumber);


uint16_t JVM_Handle_setClass(JVM_HandleNumber_t handleNumber,JVM_Class_t * class);
uint16_t JVM_Handle_getClass(JVM_HandleNumber_t handleNumber,JVM_Class_t * class);

uint16_t JVM_Handle_getRealAddres(JVM_HandleNumber_t handleNumber,uint32_t * addres);


uint16_t JVM_Handle_arraySetByte(JVM_HandleNumber_t handleNumber,uint16_t index,uint8_t value);
uint16_t JVM_Handle_arraySetShort(JVM_HandleNumber_t handleNumber,uint16_t index,int16_t value);
uint16_t JVM_Handle_arraySetChar(JVM_HandleNumber_t handleNumber,uint16_t index,uint16_t value);
uint16_t JVM_Handle_arraySetInt(JVM_HandleNumber_t handleNumber,uint16_t index,uint32_t value);
uint16_t JVM_Handle_arraySetLong(JVM_HandleNumber_t handleNumber,uint16_t index,uint64_t value);
uint16_t JVM_Handle_arraySetFloat(JVM_HandleNumber_t handleNumber,uint16_t index,float value);
uint16_t JVM_Handle_arraySetDouble(JVM_HandleNumber_t handleNumber,uint16_t index,double value);
uint16_t JVM_Handle_arraySetReference(JVM_HandleNumber_t handleNumber,uint16_t index,JVM_HandleNumber_t reference);
uint16_t JVM_Handle_arraySetLenght(JVM_HandleNumber_t handleNumber,int16_t lenght);


uint16_t JVM_Handle_arrayGetByte(JVM_HandleNumber_t handleNumber,uint16_t index,int8_t * value);
uint16_t JVM_Handle_arrayGetShort(JVM_HandleNumber_t handleNumber,uint16_t index,int16_t * value);
uint16_t JVM_Handle_arrayGetChar(JVM_HandleNumber_t handleNumber,uint16_t index,uint16_t * value);
uint16_t JVM_Handle_arrayGetInt(JVM_HandleNumber_t handleNumber,uint16_t index,int32_t * value);
uint16_t JVM_Handle_arrayGetLong(JVM_HandleNumber_t handleNumber,uint16_t index,int64_t * value);
uint16_t JVM_Handle_arrayGetFloat(JVM_HandleNumber_t handleNumber,uint16_t index,float * value);
uint16_t JVM_Handle_arrayGetDouble(JVM_HandleNumber_t handleNumber,uint16_t index,double * value);
uint16_t JVM_Handle_arrayGetReference(JVM_HandleNumber_t handleNumber,uint16_t index,JVM_HandleNumber_t *reference);
uint16_t JVM_Handle_arrayGetLenght(JVM_HandleNumber_t handleNumber,int16_t * lenght);


uint16_t JVM_Handle_instanceSetByte(JVM_HandleNumber_t handleNumber,uint16_t index,uint8_t value);
uint16_t JVM_Handle_instanceSetShort(JVM_HandleNumber_t handleNumber,uint16_t index,int16_t value);
uint16_t JVM_Handle_instanceSetChar(JVM_HandleNumber_t handleNumber,uint16_t index,uint16_t value);
uint16_t JVM_Handle_instanceSetInt(JVM_HandleNumber_t handleNumber,uint16_t index,uint32_t value);
uint16_t JVM_Handle_instanceSetLong(JVM_HandleNumber_t handleNumber,uint16_t index,uint64_t value);
uint16_t JVM_Handle_instanceSetFloat(JVM_HandleNumber_t handleNumber,uint16_t index,float value);
uint16_t JVM_Handle_instanceSetDouble(JVM_HandleNumber_t handleNumber,uint16_t index,double value);
uint16_t JVM_Handle_instanceSetReference(JVM_HandleNumber_t handleNumber,uint16_t index,JVM_HandleNumber_t reference);
//uint16_t JVM_Handle_instanceSetClass(JVM_HandleNumber_t handleNumber,JVM_Class_t * class);


uint16_t JVM_Handle_instanceGetByte(JVM_HandleNumber_t handleNumber,uint16_t index,int8_t * value);
uint16_t JVM_Handle_instanceGetShort(JVM_HandleNumber_t handleNumber,uint16_t index,int16_t * value);
uint16_t JVM_Handle_instanceGetChar(JVM_HandleNumber_t handleNumber,uint16_t index,uint16_t * value);
uint16_t JVM_Handle_instanceGetInt(JVM_HandleNumber_t handleNumber,uint16_t index,int32_t * value);
uint16_t JVM_Handle_instanceGetLong(JVM_HandleNumber_t handleNumber,uint16_t index,int64_t * value);
uint16_t JVM_Handle_instanceGetFloat(JVM_HandleNumber_t handleNumber,uint16_t index,float * value);
uint16_t JVM_Handle_instanceGetDouble(JVM_HandleNumber_t handleNumber,uint16_t index,double * value);
uint16_t JVM_Handle_instanceGetReference(JVM_HandleNumber_t handleNumber,uint16_t index,JVM_HandleNumber_t *reference);
//uint16_t JVM_Handle_instanceGetClass(JVM_HandleNumber_t handleNumber,JVM_Class_t * class);


uint16_t JVM_Handle_staticSetByte(JVM_HandleNumber_t handleNumber,uint16_t index,uint8_t value);
uint16_t JVM_Handle_staticSetShort(JVM_HandleNumber_t handleNumber,uint16_t index,int16_t value);
uint16_t JVM_Handle_staticSetChar(JVM_HandleNumber_t handleNumber,uint16_t index,uint16_t value);
uint16_t JVM_Handle_staticSetInt(JVM_HandleNumber_t handleNumber,uint16_t index,uint32_t value);
uint16_t JVM_Handle_staticSetLong(JVM_HandleNumber_t handleNumber,uint16_t index,uint64_t value);
uint16_t JVM_Handle_staticSetFloat(JVM_HandleNumber_t handleNumber,uint16_t index,float value);
uint16_t JVM_Handle_staticSetDouble(JVM_HandleNumber_t handleNumber,uint16_t index,double value);
uint16_t JVM_Handle_staticSetReference(JVM_HandleNumber_t handleNumber,uint16_t index,JVM_HandleNumber_t reference);



uint16_t JVM_Handle_staticGetByte(JVM_HandleNumber_t handleNumber,uint16_t index,int8_t * value);
uint16_t JVM_Handle_staticGetShort(JVM_HandleNumber_t handleNumber,uint16_t index,int16_t * value);
uint16_t JVM_Handle_staticGetChar(JVM_HandleNumber_t handleNumber,uint16_t index,uint16_t * value);
uint16_t JVM_Handle_staticGetInt(JVM_HandleNumber_t handleNumber,uint16_t index,int32_t * value);
uint16_t JVM_Handle_staticGetLong(JVM_HandleNumber_t handleNumber,uint16_t index,int64_t * value);
uint16_t JVM_Handle_staticGetFloat(JVM_HandleNumber_t handleNumber,uint16_t index,float * value);
uint16_t JVM_Handle_staticGetDouble(JVM_HandleNumber_t handleNumber,uint16_t index,double * value);
uint16_t JVM_Handle_staticGetReference(JVM_HandleNumber_t handleNumber,uint16_t index,JVM_HandleNumber_t *reference);

#endif /* JVM_REFERENCE_H_ */
